/*
 * @Author: 杨光辉(GerhardYang)
 * @Date: 2020-12-14 13:09:24
 * @LastEditors: 杨光辉(GerhardYang)
 * @LastEditTime: 2021-06-04 12:15:45
 * @Description: file content
 * @Copyright: 超图软件华中平台客户中心 (SuperMap Software Co., Ltd. -Central China Platform)
 */

import L from "leaflet";

export default (clickedMarker) => {
  let poiSearchInput = document.getElementById("poi-search-input").value;
  let es_title = document
    .getElementById("poi-search-input")
    .getAttribute("es-title");
  let poiSearchSelect = document.getElementById("poi-search-select").value;

  //计算正72变形代替圆
  let radius = poiSearchSelect * 1.0364200698897908453189564927571e-5;
  let centerX = clickedMarker._latlng.lng;
  let centerY = clickedMarker._latlng.lat;
  let x, y, corner;
  if (radius <= 0 || !centerX || !centerY) {
    return;
  }

  let circlePoints = [];
  for (let i = 0; i <= 360; i += 5) {
    corner = (i * Math.PI) / 180;
    x = radius * Math.cos(corner) + centerX;
    y = radius * Math.sin(corner) + centerY;
    circlePoints.push([y, x]);
  }
  circlePoints.push(circlePoints[0]);
  let queryCircle = L.polygon(circlePoints, {
    color: "red",
    fill: true,
    fillOpacity: 0.1,
  });

  return {
    es_title: es_title,
    poiSearchInput: poiSearchInput,
    queryCircle: queryCircle,
    distance: poiSearchSelect,
  };
};
